package wangwenjun.phase2.concurrencypattern.eventbus.google.demo04;

import com.google.common.eventbus.EventBus;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

/**
 * @author ChangLiang
 * @date 2020/6/19
 */
@Slf4j
public class AppTest {

    @Test
    @DisplayName("test hierarchical event")
    public void test(){
        EventBus eventBus = new EventBus();
        eventBus.register(new FruitEatenListener());
        Fruit apple = new Apple("aaa");
        eventBus.post(apple);
        log.info("post the apple eaten event:{}",apple);
        /**
         * output:
         * apple has been eaten [Apple{Name=aaa}]
         * fruit has been eaten [Apple{Name=aaa}]
         * post the apple eaten event:Apple{Name=aaa}
         */
    }

    @Test
    @DisplayName("test hierarchical event")
    public void test2(){
        EventBus eventBus = new EventBus();
        eventBus.register(new FruitEatenListener());
        Apple apple = new Apple("aaa");
        eventBus.post(apple);
        log.info("post the apple eaten event:{}",apple);
        /**
         * output:
         * apple has been eaten [Apple{Name=aaa}]
         * fruit has been eaten [Apple{Name=aaa}]
         * post the apple eaten event:Apple{Name=aaa}
         */
    }

    @Test
    @DisplayName("test hierarchical event")
    public void test3(){
        EventBus eventBus = new EventBus();
        eventBus.register(new FruitEatenListener());
        Fruit fruit = new Fruit("a Fruit");
        eventBus.post(fruit);
        log.info("post the apple eaten event:{}",fruit);
        /**
         * output:
         * fruit has been eaten [Fruit{Name=a Fruit}]
         * post the apple eaten event:Fruit{Name=a Fruit}
         */
    }
}
